//
//  ActivistViewController.m
//  TheRoadAD
//
//  Created by baixue on 16/8/12.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "ActivistViewController.h"
#import "BSSquareCell.h"

@interface ActivistViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *backView;
@property (nonatomic ,strong) UICollectionView *collectionView;
@end

#define  margin  5
#define  cellWH  (Screen_Width - 10*5)/3
static NSString *const ID = @"BSSquareCell";
@implementation ActivistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"改装";
   
    
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_home_meitu_1"] style:UIBarButtonItemStylePlain target:self action:@selector(backItem)];
    
 
    [self setUpFooterView];
}

-(void)backItem {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}


//创建流水布局
-(void)setUpFooterView{
    // 1.创建流水布局
    UICollectionViewFlowLayout *layout = ({
        
        // 1.创建流水布局
        UICollectionViewFlowLayout *layout =  [[UICollectionViewFlowLayout alloc] init];
        
        // 2.设置流水布局属性
        
        // 2.1设置cell尺寸
        layout.itemSize = CGSizeMake(cellWH, cellWH);
        
        // 2.2 设置cell之间间距
        layout.minimumLineSpacing = margin;
        
        layout;
    });
    
    // 2.创建UICollectionView
    UICollectionView *collectionView = ({
        
        // 1.创建UICollectionView
        UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 20, Screen_Width, cellWH) collectionViewLayout:layout];
        
        
        
        // 2.设置数据源 -> 要UICollectionView展示数据
        collectionView.dataSource = self;
        collectionView.delegate = self;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        collectionView.showsHorizontalScrollIndicator = NO;
        
        
        // 3. 注册cell
        [collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([BSSquareCell class]) bundle:nil] forCellWithReuseIdentifier:ID];
        
        // 4.不允许collectionView滚动
        // 取消弹簧效果
        //        collectionView.bounces = NO;
        //        collectionView.scrollEnabled = NO;
        collectionView.backgroundColor = [UIColor whiteColor];
        
        
        collectionView;
        
    });
    
    _collectionView = collectionView;
    
    // 3.设置collectionView为tableView的footView
    // 设置tableView的footView,高度由我们自己决定,宽度,位置都是控制不了
    [_backView addSubview:collectionView];
    
    
    
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    
    return UIEdgeInsetsMake(0, 10, 0, 0);
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    BSSquareCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    //     获取模型
    //     BSSquareItem *item = self.squareList[indexPath.row];
    //
    //     cell.item = item;
    
    return cell;
}

//每个item的点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 9;
    
    
}

@end
